from time import sleep
from threading import Thread, Lock


class Account(object):
    __slots__ = ('_money', '_balace', 'lock')

    def __init__(self, money):
        self._balace = 0
        self._lock = Lock()
        
    def deposit(self, money):
        self._lock.acquire()
        try:
            new_balance = self._balace + money
            sleep(0.01)
            self._balace = new_balance
        finally:
            self._lock.release()

    @property
    def balace(self):
        return self._balace


class Text(Thread):

    def __init__(self, account, money):
        super.__init__()
        self._account = account
        self._money = money

    def run(self):
        self._account.deposit(self._money)


def main():
    account = Account()
    thread = []
    for _ in range(1000):
        t = Text(account, 1)
        thread.append(t)
        t.start()
    for t in thread:
        t.join()
    print('账户余额为: ￥%d元' % account.balance)


if __name__ == "__main__":
    main()